<template>
  <div v-show="true">
    <div v-show="totalShadeShow" id="_totalWindowShade" style="display:block; position:absolute; overflow:auto; z-index:11000; top:0; left:0; right:0; bottom:0;background-color:rgba(0,0,0,0.3)"></div>
    <el-popover ref="popover1" placement="bottom" width="60" v-model="advanceVisible" trigger="hover">
      <div dir="ltr" class="dhx_toolbar_poly_18_dhx_skyblue">
        <table class="buttons_cont" cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
          <tbody>
          <tr v-for="(val,i) in advanceShowArray" :key="i"
              class="tr_btn"
              @click="choosePage(val)"
              onmouseover="this.className='tr_btn dhx_toolbar_over'"
              onmouseout="this.className='tr_btn'">
            <td class="td_btn_txt">{{bpmcoreI18n[val]}}</td>
          </tr>
          </tbody>
        </table>
      </div>
    </el-popover>
    <div class="head jlayoutBetween">
      <div class="btnleft">
        <button class="btn" v-show="showLeft" @click="navBtnClicked('main')">{{bpmcoreI18n.main}}</button>
        <button class="btn" v-show="showLeft" @click="navBtnClicked('history')">{{bpmcoreI18n.history}}</button>
        <button class="btn" v-show="showLeft" @click="navBtnClicked('diagram')">{{bpmcoreI18n.processDiagram}}</button>
      </div>
      <!--href="javascript:closeWin();"-->
      <div class="btnright">
        <a class="abtn"
           v-show="true"
           @click="closeWindows"><i class="aicon i6"></i>{{bpmcoreI18n.close}}</a>
        <!--@click="closeWindows"-->
        <a class="abtn" @click="cancel"
           v-show="indexOfShowArray('cancel')"><i class="aicon i5"></i>{{bpmcoreI18n.cancel}}</a>
        <a class="abtn"
           v-show="indexOfShowArray('advance')"
           v-popover:popover1><i class="aicon i4"></i>{{bpmcoreI18n.advance}}</a>
        <a class="abtn" @click="print"
           v-show="indexOfShowArray('print')"><i class="aicon i7"></i>{{bpmcoreI18n.print}}</a>
        <a class="abtn" @click="save"
           v-show="indexOfShowArray('save')"><i class="aicon i3"></i>{{bpmcoreI18n.save}}</a>
        <a class="abtn" @click="reject"
           v-show="indexOfShowArray('reject')"><i class="aicon i2"></i>{{bpmcoreI18n.reject}}</a>
        <a class="abtn" @click="submit"
           v-show="indexOfShowArray('submit')"><i class="aicon i1"></i>{{bpmcoreI18n.submit}}</a>
      </div>
    </div>

    <!--下一环节弹框-->
    <el-dialog :showTitle="false"
                  :visible.sync="isFlowDialogVisible"
                  :width="saberDialogWidth">
      <bpm-d-submitstepdialog v-if = "target && completeTaskType.completeTaskTypeNext=== target.completeTaskType"
                              @completeStepOKBtnClicked="completeStepOKBtnClicked"/>
      <bpm-d-submittaskdialog v-if = "target && completeTaskType.completeTaskTypeSame=== target.completeTaskType"
                              @completeTaskOKBtnClicked="completeTaskOKBtnClicked"/>
      <bpm-d-submitprocessdialog v-if = "target && completeTaskType.completeTaskTypeComplete=== target.completeTaskType"
                              @completeProcessOKBtnClicked="completeProcessOKBtnClicked"/>
      <bpm-d-submitpooldialog v-if = "target && completeTaskType.completeTaskTypePool=== target.completeTaskType"
                                 @completePoolOKBtnClicked="completePoolOKBtnClicked"/>
    </el-dialog>
    <!--驳回弹框-->
    <el-dialog :showTitle="false"
                  :visible.sync="isRejectFlowDialogVisible"
                  width="600px">
      <bpm-d-rejectdialog @rejectOKBtnClicked="rejectOKBtnClicked"/>
    </el-dialog>
    <!--加签转办选人弹框 以及 通知弹框-->
    <el-dialog :showTitle="true"
                  :visible.sync="isChoosePersonDialogVisible"
                  width="998px">
      <div v-show="isInformTextVisible">
        <table width="100%">
          <tr>
            <td class="tdy" style="text-align:right;padding-right:10px" id="msgComments">{{bpmcoreI18n.informComments}}</td>
            <td class="tde" style="width:85%">
              <textarea style="width:90%;height:30px" id="infrom_comments" v-model="displayInformComments"></textarea>
              <font color="blue" id="_infromRemnant">({{showInformInputLength}}/300)</font>
            </td>
          </tr>
        </table>
      </div>
      <bpm-d-personchoose @selectClicked="choosePersonSelectClicked"
                          @closeClicked="choosePersonCloseClicked"
                          :multSelect="personChooseMultSelect"/>
    </el-dialog>
    <!--加签转办弹框-->
    <el-dialog :showTitle="false"
                  :visible.sync="isReassignFlowDialogVisible"
                  width="600px">
      <bpm-d-reassigndialog @reassignOKBtnClicked="reassignOKBtnClicked"
                            :showReassignUser = "showReassignUser"/>
    </el-dialog>

  </div>
</template>

<script>
import JQ from 'jquery'
import {mapState, mapActions} from 'vuex'

export default {
  name: 'bpmDNavbar',
  data () {
    return {
      showLeft: true,
      // submitFlowLoading: false,
      // rejectFlowLoading: false,
      // reassignFlowLoading: false,
      advanceVisible: false,
      chooseAdvance: '', // 选择的高级-类型
      isChoosePersonDialogVisible: false,
      isInformTextVisible: false, // 通知的文本框
      informReceivers: [], // 通知人员
      chooseUid: '', // 选人框选择的人员
      personChooseMultSelect: false, // 选人框多选控制
      showReassignUser: '' // 传递给加签转办组件的displayName
    }
  },
  props: {
    hasPrint: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    ...mapState(['totalShadeShow', 'C_TASK_TYPE_INVOLVE', 'C_INST_STATUS_DRAFT', 'C_COMPLETE_TYPE_COMPLETEINVOLVE', 'C_OPERATION_REASSIGN', 'C_OPERATION_INVOLVE', 'advanceEnum', 'rejectTo', 'rejectActivities', 'isReassignVerify', 'isSubmitVerify', 'isConfirmVerify', 'isRejectVerify', 'isRejectConfirmVerify', 'isFlowDialogVisible', 'isRejectFlowDialogVisible', 'isReassignFlowDialogVisible', 'flowTypeEnum', 'flowType', 'isStartProc', 'targetUsers', 'approvalType']),
    ...mapState(['isExistAttachments', 'informComments', 'isDuplicated', 'bpmcoreI18n', 'hsInput', 'task', 'inst', 'activity', 'reassignType', 'reassignUserId', 'bizData', 'comments', 'completeTaskType', 'lang', 'userId', 'tsId', 'target']),
    displayInformComments: {
      get () {
        return this.informComments
      },
      set (value) {
        this.setInformComments(value)
      }
    },
    showInformInputLength: function () {
      return this.informComments.length + ''
    },
    // cancel advance save reject submit显隐控制
    btnShowArray: function () {
      console.log('btnShowArray activity', this.activity)
      console.log('btnShowArray flowType', this.flowType)
      let showArray = []
      if (this.hasPrint === true) {
        showArray.push('print')
      }
      if (this.flowType === this.flowTypeEnum.view) {
        return showArray
      }
      if (this.activity && this.activity.operations) {
        let currActivity = this.activity
        let operation = currActivity.operations
        operation.enSubmit && showArray.push('submit')
        operation.enSave && showArray.push('save')
        operation.enReject && showArray.push('reject')
        operation.enPrint && showArray.push('print')
        operation.enDelete && showArray.push('cancel')
        // 加签任务不显示advance
        if ((operation.enInform || operation.enReassign || operation.enInvolve) && this.task.taskType !== this.C_TASK_TYPE_INVOLVE) {
          showArray.push('advance')
        }
        operation.enDiagram && showArray.push('diagram')
        operation.enHistory && showArray.push('history')
        operation.enHelp && showArray.push('help')
      }
      console.log('nav btnShowArray', showArray)
      return showArray
    },
    // inform reassign involve显隐控制
    advanceShowArray: function () {
      console.log('advanceShowArray activity', this.activity)
      console.log('btnShowArray flowType', this.flowType)
      if (this.flowType === this.flowTypeEnum.view) {
        return []
      }
      if (this.activity && this.activity.operations) {
        let currActivity = this.activity
        let operation = currActivity.operations
        let showArray = []
        operation.enInform && showArray.push('inform')
        operation.enReassign && showArray.push('reassign')
        operation.enInvolve && showArray.push('involve')
        console.log('nav advanceShowArray', showArray)
        return showArray
      }
      return []
    },
    saberDialogWidth: function () {
      if (this.completeTaskType.completeTaskTypeSame === this.target.completeTaskType ||
         this.completeTaskType.completeTaskTypeComplete === this.target.completeTaskType ||
        this.completeTaskType.completeTaskTypePool === this.target.completeTaskType) {
        return '600px'
      } else {
        return '880px'
      }
    }
  },
  watch: {
    isSubmitVerify (curVal, oldVal) {
      if (curVal === true && oldVal === false) {
        console.log('watch isSubmitVerify-> can do flow ')
        console.log('watch isSubmitVerify-> old val : ', oldVal)
        console.log('watch isSubmitVerify-> cur val : ', curVal)
        this.doRetrieveNextActivity()
      }
    },
    isConfirmVerify (curVal, oldVal) {
      if (curVal === true && oldVal === false) {
        console.log('watch isConfirmVerify-> can do flow ')
        console.log('watch isConfirmVerify-> old val : ', oldVal)
        console.log('watch isConfirmVerify-> cur val : ', curVal)
        // 加遮罩层
        // this.submitFlowLoading = true
        this.$store.state.totalShadeShow = true
        let self = this
        setTimeout(() => {
          console.log('submit time out......')
          self.doSubmitTask()
          this.$store.state.totalShadeShow = false
        }, 100)
      }
    },
    isRejectVerify (curVal, oldVal) {
      if (curVal === true && oldVal === false) {
        console.log('watch isRejectVerify-> can do flow ')
        console.log('watch isRejectVerify-> old val : ', oldVal)
        console.log('watch isRejectVerify-> cur val : ', curVal)
        this.doRetrieveRejectPath()
      }
    },
    isRejectConfirmVerify (curVal, oldVal) {
      if (curVal === true && oldVal === false) {
        console.log('watch isRejectConfirmVerify-> can do flow ')
        console.log('watch isRejectConfirmVerify-> old val : ', oldVal)
        console.log('watch isRejectConfirmVerify-> cur val : ', curVal)
        // 加遮罩层
        this.$store.state.totalShadeShow = true
        // this.rejectFlowLoading = true
        let self = this
        setTimeout(() => {
          console.log('reject time out......')
          self.doRejectTask()
          this.$store.state.totalShadeShow = false
        }, 100)
      }
    },
    isReassignVerify (curVal, oldVal) {
      if (curVal === true && oldVal === false) {
        console.log('watch isReassignVerify-> can do flow ')
        console.log('watch isReassignVerify-> old val : ', oldVal)
        console.log('watch isReassignVerify-> cur val : ', curVal)
        // 弹加签转办提示框
        this.setIsReassignFlowDialogVisible(true)
      }
    }
  },
  methods: {
    ...mapActions(['genBtNo', 'checkAttachment', 'inform', 'setComments', 'setInformComments', 'checkIsDuplicated', 'setIsDuplicated', 'setMainVisible', 'setDiagramVisible', 'setHistoryVisible', 'retrieveTaskDones', 'cancelProcess', 'setTask', 'setInst', 'setActivity', 'saveDraft', 'setReassignType', 'setReassignUserId', 'reassignTask', 'setIsReassignFlowDialogVisible', 'rejectTask', 'setRejectTo', 'setIsSubmitVerify', 'setIsConfirmVerify', 'setIsRejectVerify', 'setIsRejectConfirmVerify', 'setIsReassignVerify', 'setIsRejectFlowDialogVisible', 'setRejectActivities', 'retrieveRejectPaths', 'completeTask', 'retrieveNextActivity', 'startProcess', 'setIsStartProc']),
    indexOfShowArray (aStr) {
      let index = JQ.inArray(aStr, this.btnShowArray)
      return index > -1
    },
    completeStepOKBtnClicked () {
      this.$emit('confirmVerify')
      this.$store.state.totalShadeShow = false
    },
    completeTaskOKBtnClicked () {
      this.$emit('confirmVerify')
      this.$store.state.totalShadeShow = false
    },
    completeProcessOKBtnClicked () {
      this.$emit('confirmVerify')
      this.$store.state.totalShadeShow = false
    },
    completePoolOKBtnClicked () {
      this.$emit('confirmVerify')
      this.$store.state.totalShadeShow = false
    },
    rejectOKBtnClicked () {
      this.$emit('rejectConfirmVerify')
      this.$store.state.totalShadeShow = false
    },
    reassignOKBtnClicked () {
      this.doReassignTask()
      this.$store.state.totalShadeShow = false
    },
    // 加签、转办、通知
    choosePage (advanceType) {
      // 这里执行速度很快，没有ajax执行，不需要遮罩层
      this.setComments(this.lang === 'zh' ? '同意' : 'OK')
      this.chooseAdvance = advanceType
      console.log(this.chooseAdvance)
      this.advanceVisible = false
      this.isChoosePersonDialogVisible = true
      // 文本框以及是否可选多人控制
      if (advanceType === this.advanceEnum.inform) {
        this.personChooseMultSelect = true
        this.isInformTextVisible = true
      } else {
        this.personChooseMultSelect = false
        this.isInformTextVisible = false
      }
    },
    // 选人组件调用的方法
    choosePersonSelectClicked (person) {
      console.log('reassign choosen person:', person)
      this.isChoosePersonDialogVisible = false
      if (!(person && person.length > 0)) {
        this.alert(this.bpmcoreI18n.choosePerson)
        this.isChoosePersonDialogVisible = true
        return
      }
      if (person && person.length > 0) {
        // 不允许加签转办给自己
        if (person[0].uid === this.task.userId) {
          if (this.chooseAdvance === this.C_OPERATION_REASSIGN) {
            this.alert(this.bpmcoreI18n.msgCanNotTurndoSelf)
          } else if (this.chooseAdvance === this.C_OPERATION_INVOLVE) {
            this.alert(this.bpmcoreI18n.msgCanNotInvolveSelf)
          }
          return
        }
        this.chooseUid = person[0].uid
        this.showReassignUser = person[0].cn + '(' + person[0].uid + ')'
        // 如果选人不为空：
        // 1.加签转办需要校验逻辑，然后显示加签转办页面
        // 2.通知则不需要校验，直接弹框，点击确认后调用通知接口，并关闭弹框
        console.log('this.chooseAdvance--->', this.chooseAdvance)
        if (this.chooseAdvance === this.C_OPERATION_REASSIGN || this.chooseAdvance === this.C_OPERATION_INVOLVE) {
          this.setReassignType(this.chooseAdvance)
          this.setReassignUserId(this.chooseUid)
          this.$emit('reassignVerify')
          this.$store.state.totalShadeShow = false
        }
      }
      if (this.chooseAdvance === this.advanceEnum.inform) {
        if (this.informComments.trim() === '') {
          this.alert(this.bpmcoreI18n.fillInformComments)
          this.isChoosePersonDialogVisible = true
          return
        }
        console.log('informComments--------->', this.informComments)
        for (var i = 0; i < person.length; i++) {
          this.informReceivers[i] = person[i].uid
        }
        this.inform({me: this})
      }
    },
    choosePersonCloseClicked () {
      this.isChoosePersonDialogVisible = false
    },
    doRetrieveNextActivity () {
      if (this.inst.status === '40') {
        // 1. 防止用户发起后，从草稿再次发起
        this.setIsDuplicated(false)
        this.checkIsDuplicated({me: this})
        if (this.isDuplicated) {
          this.alert(this.bpmcoreI18n.msgTaskHasBeenFinieshd)
          return
        }
        console.log('navbar inst genBtNo ->', this.inst)
        // 2. save draft.
        this.saveDraft({me: this})
      }
      // 判断是否是被加签任务，完成加签，完成加签接口不需要传输reassignUserId
      if (this.task.taskType === '2' ||
        (this.task.afUserId && this.task.afUserId != null && this.task.taskType === '5')) {
        this.setReassignType(this.C_COMPLETE_TYPE_COMPLETEINVOLVE)
        this.setReassignUserId('')
        this.showReassignUser = this.task.afUserName
        this.setComments(this.lang === 'zh' ? '同意' : 'OK')
        this.setIsReassignFlowDialogVisible(true)
      } else {
        let self = this
        console.log('doRetrieveNextActivity flowType-> ', this.flowType)
        if (this.flowType === this.flowTypeEnum.draft) {
          console.log('saveDraft tsId-> ', this.tsId)
          console.log('saveDraft inst-> ', this.inst)
          console.log('saveDraft task-> ', this.task)
          // 获取发起弹框，调用发起接口前，先保存草稿，之后调用接口就可以一直传输tsid
          console.log('nav header btn click -> back into nav draft child -> 调用发起接口参数为false')
          this.setIsStartProc(false)
          this.startProcess({
            me: this,
            bizFailFunc: function () {
              self.setIsSubmitVerify(false)
              self.setIsConfirmVerify(false)
            }
          })
        } else if (this.flowType === this.flowTypeEnum.approve) {
          // 获取审批弹框
          console.log('nav header btn click -> back into nav approve child -> 调用获取下一环节接口')
          this.retrieveNextActivity({
            me: this,
            bizFailFunc: function () {
              console.log('doRetrieveNextActivity bizFailFunc')
              self.setIsSubmitVerify(false)
              self.setIsConfirmVerify(false)
            }
          })
        }
      }
    },
    doSubmitTask () {
      let self = this
      if (this.flowType === this.flowTypeEnum.draft) {
        // 正式发起流程
        console.log('nav header btn click -> back into nav draft child -> 调用发起接口参数为true')
        this.setIsStartProc(true)
        this.startProcess({
          me: this,
          succFunc: function (data) {
            if (self.isStartProc === true) {
              // 关闭窗口
              self.closeWindows()
            }
          },
          failFunc: function () {
            if (self.isStartProc === true) {
              console.log('doSubmitTask fail')
              self.setIsSubmitVerify(false)
              self.setIsConfirmVerify(false)
            }
          },
          bizFailFunc: function () {
            // 执行成功，但返回异常码，初始化校验位
            console.log('doSubmitTask biz fail')
            self.setIsSubmitVerify(false)
            self.setIsConfirmVerify(false)
          }
        })
      } else if (this.flowType === this.flowTypeEnum.approve) {
        // 提交审批任务
        console.log('nav header btn click -> back into nav approve child -> 调用完成任务接口')
        console.log('执行完成服务')
        this.completeTask({
          me: this,
          succFunc: function (data) {
            // 关闭窗口
            self.closeWindows()
          },
          failFunc: function () {
          // 服务执行失败中断，初始化校验位
            console.log('doSubmitTask fail')
            self.setIsSubmitVerify(false)
            self.setIsConfirmVerify(false)
          },
          bizFailFunc: function () {
            // 执行成功，但返回异常码，初始化校验位
            console.log('doSubmitTask biz fail')
            self.setIsSubmitVerify(false)
            self.setIsConfirmVerify(false)
          }
        })
      }
    },
    doRetrieveRejectPath () {
      let self = this
      console.log('nav header btn click -> back into nav approve child -> 调用获取驳回路径接口')
      this.retrieveRejectPaths({
        me: this,
        bizFailFunc: function () {
          self.setIsRejectVerify(false)
          self.setIsRejectConfirmVerify(false)
        }
      })
    },
    doRejectTask () {
      let self = this
      console.log('nav header btn click -> back into nav approve child -> 调用驳回任务接口')
      this.rejectTask({
        me: this,
        succFunc: function (data) {
          // 关闭窗口
          self.closeWindows()
        },
        failFunc: function () {
          // 服务执行失败中断
          console.log('doRejectTask fail')
        },
        bizFailFunc: function () {
          // 执行成功，但返回异常码，初始化校验位
          console.log('doRejectTask bizFail')
          self.setIsRejectVerify(false)
          self.setIsRejectConfirmVerify(false)
        }
      })
    },
    doReassignTask () {
      let self = this
      console.log('nav header btn click -> back into nav approve child -> 调用加签转办任务接口')
      console.log('reject time out......')
      self.reassignTask({
        me: this,
        succFunc: function (data) {
          if (self.reassignType === this.C_COMPLETE_TYPE_COMPLETEINVOLVE) {
            self.alert(self.bpmcoreI18n.msgInvolveSuccess)
          } else if (self.reassignType === this.C_OPERATION_REASSIGN) {
            self.alert(self.bpmcoreI18n.msgTurndoSuccess)
          } else if (self.reassignType === this.C_OPERATION_INVOLVE) {
            self.alert(self.bpmcoreI18n.msgInvolveSuccess)
          }
          // 关闭窗口
          self.closeWindows()
        },
        failFunc: function () {
          // 执行失败后，服务执行失败中断
          console.log('doReassignTask fail')
        },
        bizFailFunc: function () {
          // 执行成功，但返回异常码，初始化校验位
          console.log('doReassignTask bizFail')
          self.setIsReassignVerify(false)
        }
      })
    },
    submit () {
      // 加遮罩层
      this.$store.state.totalShadeShow = true
      setTimeout(() => {
        // 生成表单号，在第三方接口中就会跳过，在发起接口中生成单号就迟了，很多SAP接口都用到了单号
        if (!this.inst.btNo) {
          this.genBtNo({me: this})
        }
        this.setComments(this.lang === 'zh' ? '同意' : 'OK')
        this.$emit('submitVerify')
        this.$store.state.totalShadeShow = false
      }, 100)
    },
    reject () {
      // 加遮罩层
      this.$store.state.totalShadeShow = true
      setTimeout(() => {
        this.setComments('')
        this.$emit('rejectVerify')
        this.$store.state.totalShadeShow = false
      }, 100)
    },
    save () {
      // 加遮罩层
      this.$store.state.totalShadeShow = true
      setTimeout(() => {
        // 1.判断任务是否处于当前环节及办理人，即是否有保存权限
        this.setIsDuplicated(false)
        this.checkIsDuplicated({me: this})
        if (this.isDuplicated) {
          this.alert(this.bpmcoreI18n.msgTaskHasBeenFinieshd)
          this.$store.state.totalShadeShow = false
          return
        }
        // 2. 不能有附件
        let isNeedCheck = this.isNeedCheckAttachment()
        if (isNeedCheck) {
          this.checkAttachment({me: this})
        }
        console.log('this.isExistAttachments--->', this.isExistAttachments)
        if (this.isExistAttachments) {
          this.$store.state.totalShadeShow = false
          return
        }
        // 3.save draft
        this.saveDraft({me: this})
        // 调用业务保存
        this.$emit('save')
        console.log('save done')
        this.$store.state.totalShadeShow = false
      }, 100)
    },
    cancel () {
      // 加遮罩层
      this.$store.state.totalShadeShow = true
      let self = this
      setTimeout(() => {
        this.cancelProcess({
          me: this,
          succFunc: function (data) {
            // 关闭窗口
            self.closeWindows()
          },
          failFunc: function () {
            // 执行失败后去掉遮罩，服务执行失败中断
            console.log('去掉遮罩层')
          }
        })
        this.$store.state.totalShadeShow = false
      }, 100)
    },
    print () {
      this.$emit('print')
    },
    closeWindows () {
      console.log('关闭窗口')
      try {
        if (window.opener !== undefined && typeof (window.opener.refreshOnTwStateShange) !== 'undefined') {
          console.log('start refreshOnTwStateShange')
          window.opener.refreshOnTwStateShange()
        }
      } catch (e) {
        console.log('closeWindows try catch exception')
      }
      window.opener = null
      window.open('', '_self', '')
      window.close()
      window.location.href = 'about:blank'
    },
    // 流程图 历史 主表单切换
    navBtnClicked (btnType) {
      console.log('nav header btn click -> back into nav:', btnType)
      if (btnType === 'history') { // 历史
        this.setDiagramVisible(false)
        this.setHistoryVisible(true)
        this.setMainVisible(false)
        if (this.$store.state.countHistory === 0) {
          // 获取审批历史
          // 2.异步加载审批历史,页签起草时（hsInput.ts_piid === '-1'）不用加载
          console.log('*********hsInput.ts_piid***********', this.hsInput.ts_piid && this.hsInput.ts_piid === '-1')
          if (!(this.hsInput.ts_piid && this.hsInput.ts_piid === '-1')) {
            this.retrieveTaskDones({me: this})
            this.$store.state.countHistory = 1
          }
        }
      } else if (btnType === 'diagram') { // 流程图
        this.setDiagramVisible(true)
        this.setHistoryVisible(false)
        this.setMainVisible(false)
        if (this.$store.state.countDiagram === 0) {
          let host = window.location.protocol + '//' + window.location.host
          console.log('host----->', host)
          if (host === 'http://localhost:8080') {
            host = 'http://bpmdev02.whchem.com' // 本地调试链接开发，需要登录或者单点
          }
          if (this.inst && this.inst.id) {
            if (this.hsInput && this.hsInput.ts_piid && this.hsInput.ts_piid === '-1') {
              this.$store.state.showDiagramUrl = host + '/ECS_BPM_ADV/jsp/trdpty/processMapNew.jsp?bpdId=' + this.inst.bpdId + '&appShortName=' + this.inst.appShortName + '&snapshotId=' + this.inst.snapshotId
            } else {
              this.$store.state.showDiagramUrl = host + '/ECS_BPM_ADV/jsp/trdpty/processMapNew.jsp?bpdId=' + this.inst.bpdId + '&appShortName=' + this.inst.appShortName + '&tsPiid=' + this.inst.id + '&snapshotId=' + this.inst.snapshotId
            }
          }
          console.log('showDiagramUrl----------->', this.$store.state.showDiagramUrl)
          this.$store.state.countDiagram = 1
        }
      } else if (btnType === 'main') { // 主表单
        this.setDiagramVisible(false)
        this.setHistoryVisible(false)
        this.setMainVisible(true)
      }
    },
    isNeedCheckAttachment () {
      var isNeedCheck = false
      if (this.activity.activityName && this.activity.activityName.toLowerCase().indexOf('@draft') !== -1) {
        isNeedCheck = true
      } else if (this.C_INST_STATUS_DRAFT === this.inst.status) {
        isNeedCheck = true
      }
      return isNeedCheck
    }
  }
}
</script>

<style scoped>
  .head {
    z-index: 1000;
    top: 0;
    position: fixed;
    width: 980px;
    height: 39px;
    padding: 0 19px;
    box-sizing: border-box;
    background: url(/static/images/contentBg.png) repeat-x 0 0;
  }
  .btn {
    background: url(/static/images/contentBg.png) no-repeat -116px -122px;
    height: 24px;
    width: 60px;
    display: block;
    color: #f0f0f0;
    text-align: center;
    line-height: 24px;
    float: left;
    margin-right: 5px;
    border: 0;
    cursor: pointer;
  }

  .aicon {
    margin-top: 2px;
    width: 18px;
    height: 18px;
    float: left;
  }

  .abtn {
    color: #fff;
    display: block;
    padding: 5px;
    float: right;
    height: 14px;
    text-align: left;
    cursor: pointer;
  }

  .i1 {
    background: url(/static/images/contentBg.png) no-repeat 0 -86px;
  }

  .i2 {
    background: url(/static/images/contentBg.png) no-repeat 0 -130px;
  }

  .i3 {
    background: url(/static/images/contentBg.png) no-repeat 0 -44px;
  }

  .i4 {
    background: url(/static/images/contentBg.png) no-repeat 0 -258px;
  }

  .i5 {
    background: url(/static/images/contentBg.png) no-repeat 0 -238px;
  }

  .i6 {
    background: url(/static/images/contentBg.png) no-repeat 0 -217px;
  }
  .i7 {
    background: url(/static/images/contentBg.png) no-repeat 0 -173px;
  }
  .btnleft {
    float: left;
    width: 30%;
  }
  .btnright {
    float: right;
    width: 70%;
  }
  .dhx_toolbar_over {
    background: cornflowerblue;
  }
  .dhx_toolbar_poly_18_dhx_skyblue {
    margin: 0;
    padding: 0;
    border: #a4bed4 1px solid;
    background-color: #1C68C0;
    overflow: hidden;
    cursor: default;
    line-height: normal;
  }
  .tr_btn {
    height: 24px;
  }
  .td_btn_txt {
    width: 100%;
    font-size: 12px;
    color: #fff;
    vertical-align: middle;
    text-align: center;
  }
</style>
